package com.cr.admin.business.vip.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.cr.admin.business.topic.pojo.entity.Topic;
import com.cr.admin.business.topic.pojo.param.TopicAddParam;
import com.cr.admin.business.topic.pojo.param.TopicUpdateParam;
import com.cr.admin.business.vip.pojo.dto.VipAddParam;
import com.cr.admin.business.vip.pojo.dto.VipPasswordParam;
import com.cr.admin.business.vip.pojo.dto.VipQuery;
import com.cr.admin.business.vip.pojo.dto.VipUpdateParam;
import com.cr.admin.business.vip.pojo.entity.Vip;
import com.cr.admin.business.vip.service.VipService;
import com.cr.admin.system.pojo.dto.SysUserPasswordParam;
import com.cr.common.response.JsonResult;
import com.cr.common.response.PageData;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "110.会员资料")
@RestController
@RequestMapping("/api/bus/vip")
public class VipController {

    @Autowired
    private VipService vipService;

    @ApiOperation(value = "查询会员资料")
    @GetMapping("/profile")
    public JsonResult getProfile(VipQuery vipQuery) {
        PageData<Vip> pageData = PageData.page(vipQuery.getPageNum(), vipQuery.getPageSize(), () -> vipService.list(vipQuery));
        return JsonResult.success(pageData);
    }


    @ApiOperation(value = "新增会员")
    @PostMapping
    public JsonResult insert(@Validated @RequestBody VipAddParam vipAddParam) {
        vipService.insert(vipAddParam);
        return JsonResult.success();
    }


    @ApiOperation(value = "修改会员信息")
    @PutMapping()
    public JsonResult update(@Validated @RequestBody VipUpdateParam vipUpdateParam ) {
        vipService.updateById(vipUpdateParam);
        return JsonResult.success();
    }

    @ApiOperation(value = "查询会员详情")
    @GetMapping("{id}")
    public JsonResult getDetail(@PathVariable("id") Long id) {
        Vip vip = vipService.selectById(id);
        return JsonResult.success(vip);
    }
    @ApiOperation(value = "删除会员")
    @DeleteMapping()
    public JsonResult delete(@RequestParam(name = "ids") List<Long> ids){
        vipService.deleteByIds(ids);
        return JsonResult.success();
    }

    @ApiOperation(value = "重置密码")
    @PatchMapping("/{id}/resetPassword")
    public JsonResult resetPassword(@PathVariable("id") Long id) {
        vipService.resetPassword(id);
        return JsonResult.success();
    }
    @ApiOperation(value = "修改状态")
    @PatchMapping("/{id}/status")
    public JsonResult updateStatus(@PathVariable("id") Long id, @RequestParam("status") Integer status) {
        vipService.updateStatus(id, status);
        return JsonResult.success();
    }


}
